//
//  XMConfirmOrderViewController.m
//  XMJJ_zml
//
//  Created by 丁浩 on 2025/6/16.
//

#import "XMConfirmOrderViewController.h"
#import "XMConfirmOrderView.h"
#import "XMPayViewController.h"
#import "XMNetwork+home.h"

@interface XMConfirmOrderViewController ()

@property (nonatomic, strong) XMConfirmOrderView *confirmOrderView;

@end

@implementation XMConfirmOrderViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self creatUI];
}

- (void)creatUI {
    [self.view addSubview:self.confirmOrderView];
    if (self.meetDetailModelArr.count > 0) {
        [_confirmOrderView setContentWithModelArr:self.meetDetailModelArr];
    }
    else {
        [_confirmOrderView setContentWithMeetModelArr:self.meetBoxModelArr
                                         selectRowDic:self.selectRowDic];
    }
    XMWeakSelf;
    _confirmOrderView.payBlock = ^(NSString * _Nonnull cartIdsStr, NSString * _Nonnull payPrice) {
        if (weakSelf.meetBoxModelArr && weakSelf.meetBoxModelArr.count > 0) {
            [weakSelf creatOrderWithCartsId:cartIdsStr price:payPrice];
        }
        else {
            [weakSelf creatOrderWithServiceId:cartIdsStr price:payPrice];
        }
    };
}

//见面箱进入
- (void)creatOrderWithCartsId:(NSString *)cartIdsStr
                        price:(NSString *)priceStr {
    XMWeakSelf;
    [_Network creatOrderWithCartIds:cartIdsStr
                          addressId:@""
                            payType:@"1"
                            success:^(id  _Nonnull responseObject) {
        XMPayViewController *payVC = [[XMPayViewController alloc] init];
        payVC.orderId = [responseObject safeStringForKey:@"data"];
        payVC.priceStr = priceStr;//@"200";
        [weakSelf.navigationController pushViewController:payVC animated:YES];
    } failure:^(NSError * _Nonnull error) {

    }];
}

//直接创建订单
- (void)creatOrderWithServiceId:(NSString *)serviceId
                          price:(NSString *)priceStr {
    XMWeakSelf;
    [_Network creatOrderWithServiceId:serviceId
                              success:^(id  _Nonnull responseObject) {
        XMPayViewController *payVC = [[XMPayViewController alloc] init];
        payVC.orderId = [responseObject safeStringForKey:@"data"];
        payVC.priceStr = priceStr;//@"200";
        [weakSelf.navigationController pushViewController:payVC animated:YES];
    } failure:^(NSError * _Nonnull error) {
        
    }];
}

- (XMConfirmOrderView *)confirmOrderView {
    if (!_confirmOrderView) {
        _confirmOrderView = [[XMConfirmOrderView alloc] initWithFrame:self.view.bounds];
    }
    return _confirmOrderView;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
